package com.gomore.opple.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;

public class DeviceUtils {

    // 获取软件版本
    public static String getVersionName(Context context) {
        try {
            PackageManager packageManager = context.getPackageManager();
            PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            String version = packInfo.versionName;
            return version;
        } catch (PackageManager.NameNotFoundException e) {
        }
        return "";
    }

    public static String getDeviceId(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        //获取设备号
        String deviceId = tm.getDeviceId();
        if (deviceId == null) {
            //Android系统的唯一编号
            deviceId = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
        }
        return deviceId;
    }

    public static String getDeviceName(Context context) {
        //获取设备号
        String deviceId = android.os.Build.MODEL;
        if (deviceId == null) {
            deviceId = "";
        }
        return deviceId;
    }
}
